home *** CD-ROM | disk | FTP | other *** search
/ CGI How-To / CGI HOW-TO.iso / chap6 / 6_8 / newd_c / string.h < prev   
Encoding:
C/C++ Source or Header  |  1996-06-15  |  1.5 KB  |  78 lines

  1.  
  2. #ifndef STRING_H
  3. #define STRING_H
  4.  
  5. /*
  6.  * This file declares an Abstract data type String
  7.  * for dealing with strings in C.
  8.  */
  9.  
  10. #include <string.h>
  11.      
  12. typedef struct _string *String;
  13.  
  14. struct _string
  15. {
  16.     char *string;
  17.     int mallocedSize;
  18. };
  19.  
  20.  
  21. /* Creates a string with the initial size, and returns it */
  22.  
  23. String string_alloc(unsigned int size);
  24.  
  25. /* Frees the string and its memory */
  26.  
  27. void string_free(String str);
  28.  
  29. /* Resizes the String, will use realloc or malloc based on freeString */
  30.  
  31. void string_setSize(String str,unsigned int size,int freeString);
  32.  
  33. /* returns the size */
  34.  
  35. int string_length(String str);
  36.  
  37. /* Sets the strings data to "", without freeing the space */
  38.  
  39. void string_empty(String str);
  40.  
  41. /* Copys the data in str2 to str */
  42.  
  43. void string_setStringValue(String str,char *str2);
  44.  
  45. /* Copys the data in str2 to str , constrained by numChar*/
  46.  
  47. void string_setStringNValue(String str,char *str2, int numChar);
  48.  
  49. /* Copys the strings data and returns it*/
  50.  
  51. char * string_copyValue(String str);
  52.  
  53. /* Appends a character to the string */
  54.  
  55. void string_appendChar(String str,char c);
  56.  
  57. /* Appends a char * to the string */
  58.  
  59. void string_appendString(String str1,const char *str2);
  60.  
  61. /* Appends a char * to the string, limited by numChar */
  62.  
  63. void string_appendNString(String str1,const char *str2,int numChar);
  64.  
  65. /* Convert the string to upper case */
  66.  
  67. void string_toUpper(String str);
  68.  
  69. /* Remove the first n characters */
  70.  
  71. void string_crop(String str, int n);
  72.  
  73. /* Remove the last n characters */
  74.  
  75. void string_chop(String str, int n);
  76.  
  77. #endif
  78.